package A1_栈和队列;

import java.util.Stack;

public class LC_232用栈实现队列 {
    class MyQueue{
        Stack<Integer> stackIn=new Stack<>();
        Stack<Integer> stackOut=new Stack<>();
        public MyQueue() {
            stackIn=new Stack<>();
            stackOut=new Stack<>();
        }
        // 将元素 x 推到队列的末尾
        public void push(int x) {
            stackIn.push(x);
        }
        //从队列的开头移除并返回元素
        public int pop() {
            if(stackOut.isEmpty())
                while(!stackIn.isEmpty())
                    stackOut.push(stackIn.pop());
            return stackOut.pop();
        }
        //返回队列开头的元素
        public int peek() {
            int result=pop();
            stackOut.push(result);
            return result;
        }
        //如果队列为空，返回 true ；否则，返回 false
        public boolean empty() {
            return stackOut.isEmpty() && stackIn.isEmpty();
        }
    }
}
